import { defineComponent, getCurrentInstance, computed, ref, watch } from "vue";
import defaultProps from "../props.mjs";
const name = "ep-correlation";
const _sfc_main = defineComponent({
  name,
  props: defaultProps,
  emits: ["update:modelValue"],
  setup(props, { emit }) {
    const instance = getCurrentInstance();
    const proxy = instance == null ? void 0 : instance.proxy;
    const isDetail = computed(() => props.options.permission > 0);
    const fieldModel = computed({
      get() {
        return props.modelValue;
      },
      set(val) {
        emit("update:modelValue", val);
      }
    });
    const dialogVisible = ref(false);
    watch(dialogVisible, (val) => {
      if (val) {
        list = props.modelValue || [];
      }
    });
    let list = props.modelValue || [];
    const onCallback = (e) => {
      list = [...e];
    };
    const onSave = () => {
      const { limit, tip } = props.options;
      if (list.length > limit) {
        proxy == null ? void 0 : proxy.$message.error(tip || "超出最多关联数量");
        return false;
      }
      dialogVisible.value = false;
      emit("update:modelValue", list);
    };
    return {
      fieldModel,
      isDetail,
      dialogVisible,
      onCallback,
      onSave
    };
  }
});
export {
  _sfc_main as default
};
